package common.util;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;


public class PojoChangeToMap {

	private final static Logger logger = Logger
			.getLogger(PojoChangeToMap.class);

	public static Map<String, Object> change(Object object) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (object instanceof Integer || object instanceof String
				|| object instanceof Boolean || object instanceof Character
				|| object instanceof Double || object instanceof Float
				|| object instanceof Long) {
			map.put(object.getClass().getName(), object);
		} else {
			try {
				Method[] methods = object.getClass().getMethods();
				for (Method method : methods) {
					if (method.getName().startsWith("get")) {
						Object result = method.invoke(object, null);
						map.put(method.getName().substring(3), result);
					}
				}

			} catch (Exception e) {
				logger.error(e.getMessage(), e);
			}
		}
		return map;
	}

}
